package persistency.controller;

import java.util.ArrayList;
import java.util.Collection;

import model.Business;
import model.BusinessTypeEnum;
import model.FreeStudent;
import model.Registration;
import model.RetrainingStudent;
import persistency.ArgIO;

public class RetrainingStudentController extends BusinessController{
	private StringBuilder callableStatement;

	private static RetrainingStudentController instance = new RetrainingStudentController();
	private RetrainingStudentController(){}
	
	public static RetrainingStudentController instance(){
		return instance;
	}
	
	public boolean insertFreeStudent(FreeStudent freeStudent) {
		callableStatement = new StringBuilder("{call sp_insertretrainingstudent(?,?,?)}");
		return insert(freeStudent,callableStatement,3);
	}
	
	public RetrainingStudent getRetrainingStudent(String id){
		return (RetrainingStudent)getBusinessObject(id,new StringBuilder("{call sp_getbyidretrainingstudent(?)}"),BusinessTypeEnum.RETRAININGSTUDENT);
	}
	
	public Collection<RetrainingStudent> getAll() {
		Collection<RetrainingStudent> col = new ArrayList<RetrainingStudent>();
		col.addAll((Collection<? extends RetrainingStudent>) getBusinessObjects(new StringBuilder("{call sp_getallretrainingstudent}"),BusinessTypeEnum.RETRAININGSTUDENT));
		return col;
	}

	@Override
	public void prepare(Business business, Object[] args, int[] argsType, ArgIO[] argsIO, int i) throws Exception {
		/*
		 in studentnumber varchar(25),
    in highestdegree varchar(25),
    in retrainingreason varchar(50)
		 */
		
		RetrainingStudent retrainingStudent = (RetrainingStudent) business;
		switch (i) {
		case 0: {
			args[i] = retrainingStudent.getStudentNumber();
			argsType[i] = java.sql.Types.CHAR;
			argsIO[i] = ArgIO.IN;
			break;
		}
		case 1: {
			args[i] = retrainingStudent.getHighestDegree();
			argsType[i] = java.sql.Types.CHAR;
			argsIO[i] = ArgIO.IN;
			break;
		}
		case 2: {
			args[i] = retrainingStudent.getRetrainingReason();
			argsType[i] = java.sql.Types.CHAR;
			argsIO[i] = ArgIO.IN;
			break;
		}
		default:
			throw new Exception("Error while creating SP createCourse");
		}
		
	}
}
